<?php
/**
 * 地区信息模型
 * 
 *  @author sandy 
 */
class regionModel extends Model {
	
	public function get_children_region($page_info = array(),$parent_id = 0){
		
		$return = array('result'=>'','total'=>0);
		
		$sql = "SELECT * FROM #__region WHERE region_parent_id = $parent_id";
		
		$sql_count = "	SELECT count(*)  FROM #__region WHERE region_parent_id = $parent_id";
		
		if (!empty($page_info)){
			$this->db->set_query($sql,$page_info['offset'],$page_info['limit']);
		} else {
			$this->db->set_query($sql);
		}
		
		$return['result'] = $this->db->get_all();
		
		$this->db->set_query($sql_count);
		$return['total'] = $this->db->get_one();
				
		return $return;
	}
	
	
	public function get_region ($rid) {
		$sql = "SELECT * FROM #__region WHERE region_id = $rid";
		$this->db->set_query($sql);
		
		return $this->db->get_row();
	}
	
	public function update_region($region_info) {

		$update_info = array(
				'region_name' => $region_info['region_name'],
				'english_name' => $region_info['english_name'],
				'region_parent_id' => isset($region_info['region_parent_id']) ? $region_info['region_parent_id'] : 0,
				'abb' => $region_info['abb'],
				'code' => $region_info['code'],
		);
		
		return $this->db->update('#__region',$update_info,'region_id = '.$region_info['region_id']);
	}
}

